0.1 Introduction

In this study we will analyse economical Data of the Worldbank…

0.2 Region Mapping

To simplify the Data we will aggregate it by regions as defined by the worldbank, please see the map below…

pal = tableau_color_pal(
  palette = "Tableau 10")(10)

data("World")

World = World%>%
  filter(continent!="Antarctica")

World$wb=countrycode(sourcevar = World$iso_a3,
                        origin = "iso3c",
                         destination = "region")

World = World%>%
  filter(!is.na(wb))

ggplot(data = World) +
    geom_sf(aes(fill=wb),color="white",size=.1)+
    theme(legend.position = "none",x.axis.text="none")+
    scale_fill_tableau()+
    theme_igray() 

# tmap_mode("plot")
# 
# tm_shape(World) +
#     tm_polygons("wb",palette=pal)

0.3 Racing Bar Chart

In this section there is an animated graph

0.4 Worldbank Indicators

Now we will have a look at selected Indicators

load("worldbankindicators.RData") 

tmap_mode("view")

currentdata = worldbank_data%>%
  filter(!is.na(Values))%>%
  filter(year == 2020)%>%
  mutate(iso_a3 = 
           countrycode(sourcevar = .$iso2c,
                        origin = "iso2c",
                         destination = "iso3c"))%>%
  filter(!is.na(iso_a3))
  
vars = World%>%left_join(currentdata)

tm_shape(vars) +
    tm_polygons("Values")+
    tm_facets(by = "Indicator",free.scales=TRUE)

0.5 Inflation in Detail

0.6 Headline inflation

Headline inflation is the raw inflation figure reported through the Consumer Price Index (CPI) that is released monthly by the Bureau of Labor Statistics (BLS). The CPI calculates the cost to purchase a fixed basket of goods to determine how much inflation is occurring in the broad economy. The CPI uses a base year and indexes the current year’s prices, according to the base year’s values.

0.7 Core Inflation

Core inflation removes the CPI components that can exhibit large amounts of volatility from month to month, which can cause unwanted distortion to the headline figure. The most commonly removed factors are those relating to the costs of food and energy. Food prices can be affected by factors outside of those attributed to the economy, such as environmental shifts that cause issues in the growth of crops. Energy costs, such as oil production, can be affected by forces outside of traditional supply and demand, such as political dissent.

Now we will have a look at Inflation in further Detail.

#source("inflationdata.R")
load("inflationdata.RData")

data = data%>%
  mutate(date=as.POSIXct(date))%>%
  mutate(region = countrycode(sourcevar = data$region,
                        origin = "iso3n",
                         destination = "region")
  )%>%
  drop_na()%>%
  group_by(region,`Series Name`,date)%>%
  summarise(value=median(value,na.rm=T))%>%
  drop_na()%>%
  mutate(series = word(`Series Name`,1,-2))%>%
  nest(data = -c(region,series))%>% 
  mutate(
    test = map(data, ~ loess(.$value~as.numeric(.$date), span = .5)), # S3 list-col
    tidied = map(test, augment,se.fit=T
    )
  )%>% 
  unnest(c(tidied,data))%>%
  select(-test)%>%
  data.frame()%>%
  mutate(smooth = `.fitted`)%>%
  mutate(ref=2)%>%
  mutate(crisis=ifelse(
    date > as.POSIXct(as.Date("2008-10-19 10:15")) & date < as.POSIXct(as.Date("2010-10-19 10:15")), 1, 0))

selection = alt$selection_single(fields=list("region"), bind='legend')

chart <-
  alt$Chart()$
  encode(
    x=alt$X('date:T', axis=alt$Axis(title='Time')),
    #x = "date:T",
    #y = "smooth:Q",
    strokeWidth=alt$value(2),
    y=alt$Y('smooth:Q', axis=alt$Axis(title='Annual Inflation Rate')),
    color="region:N",
    tooltip=list('region:N','date:T'),
    opacity=alt$condition(selection, alt$value(1), alt$value(0.2))
  )$
  mark_line()$
  interactive()$
    add_selection(
    selection
  )


rule = alt$Chart(
)$mark_rule(color='red')$encode(
    y='ref:Q',
    strokeWidth=alt$value(2)
)

all = alt$layer(chart,rule,data=data)$facet('series',columns=2,title="Yearly Inflation Rates by Month by Index and Worldbank-Regions")

all

0.8 Inflation Heatmap

m = data%>%
  select(region,series,value,date)%>%
  pivot_wider(id_cols=c(date,region),names_from=series,values_from=value)

korr = m%>%
  select(-date)%>%
  nest(data=-c(region))%>%
  mutate(korr = map(data,cor),
        tidied = map(korr, tidy))%>%
  unnest(tidied)


t = data.frame(
  series = rep(data$series%>%unique,data$region%>%unique%>%length),
  region = korr$region,
  corr = korr$x
)
colnames(t)[3:6]=data$series%>%unique

t_long=t%>%
  pivot_longer(!c(series,region))


alt$Chart(t_long)$mark_rect()$encode(
    x='series:N',
    y='name:N',
    color='value:Q',
    tooltip = list("series:N","name:N","value:Q")
)$facet("region:N",columns=3)
m = data%>%
  select(region,series,value,date)%>%
  mutate(region2=region)%>%
  mutate(region=series,series=region2)%>%
  pivot_wider(id_cols=c(date,region),names_from=series,values_from=value)

korr = m%>%
  select(-date)%>%
  nest(data=-c(region))%>%
  mutate(korr = map(data,cor),
        tidied = map(korr, tidy))%>%
  unnest(tidied)


d = data%>%
  mutate(region2=region)%>%
  mutate(region=series,series=region2)

t = data.frame(
  series = rep(d$series%>%unique,d$region%>%unique%>%length),
  region = korr$region,
  corr = korr$x
)
colnames(t)[3:9]=d$series%>%unique

t_long=t%>%
  pivot_longer(!c(series,region))

alt$Chart(t_long)$mark_rect()$encode(
    x='series:N',
    alt$Y('name:N', axis=alt$Axis(ticks=FALSE, domain=FALSE)),
    color='value:Q',
    tooltip = list("series:N","name:N","value:Q")
)$facet("region:N",columns=2)